<style lang="less">
    @import './login.less';
</style>

<template>
    <div class="login">
        <div class="login-con">
            <Card icon="log-in" title="欢迎登录" :bordered="false">
                <div class="form-con">
                    <login-form ref="ggg" @on-success-valid="handleSubmit"></login-form>
                    <p class="login-tip" :class="msgError?'red':''">{{msg}}</p>
                </div>
            </Card>
        </div>
    </div>
</template>

<script>
    import LoginForm from '_c/login-form'
    import {mapActions} from 'vuex'

    export default {
        data() {
            return {
                msg: '输入手机号和密码密码',
                msgError: false
            }
        },
        components: {
            LoginForm
        },
        methods: {
            ...mapActions([
                'handleLogin',
                'getUserInfo'
            ]),
            handleSubmit({userName, password, verify}) {
                this.$Message.loading({
                    content: '登陆中。。。',

                })
                this.handleLogin({userName, password, verify}).then(res => {
                    if (res.code === 10002) {
                        this.msgError = true
                        this.$refs.ggg.changeVerifyImg()
                        for (let a in res.msg) {
                            this.msg = res.msg[a]
                            break;
                        }
                    }else if (res.code === 0) {
                        this.getUserInfo(res.data).then(res => {
                            console.log(res.code)
                            if (res.code === 0) {
                                this.$Message.success('登陆中成功')
                                this.$router.push({
                                    name: 'home'
                                })
                            }else {
                                this.msg = '请重新登陆'
                                this.msgError = true
                            }
                        })
                    }else {
                        this.msgError = true
                        this.msg = res.msg
                        this.$refs.ggg.changeVerifyImg()
                    }

                }).catch(res => {
                })
            },
            show() {

            }
        },
        mounted(){
            this.$Notice.info({
                title: '系统升级提示',
                duration: 0,
                render: h => {
                    return h('span', [
                        h('a', {
                            on: {
                                click: () => {
                                    window.open('https://dumu.withiron.com/admin_login')
                                }
                            },
                        }, 'https://dumu.withiron.com/admin_login'),
                        h('br'), h('br'),
                        '当前版本将于不久后关闭，所有功能全部移至新版（新版将有更多功能）点击进入新版，账号密码不变'
                    ])
                }
            });
        }
    }
</script>

<style>
    .red {
        color: red !important;
    }
</style>
